/**
 * Copyright (c) 2015-2015 All Rights Reserved.
 */
package com.zbest.zpay.paycore.biz.action.pay;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.stereotype.Service;

import com.zbest.common.lang.enums.BizCode;
import com.zbest.common.lang.exception.ZpayException;
import com.zbest.common.lang.validator.ValidatorUtil;
import com.zbest.zpay.service.paycore.model.PayInfoDTO;
import com.zbest.zpay.service.paycore.model.PaySubInfoDTO;
import com.zbest.zpay.service.paycore.model.PaycoreKeyEnum;
import com.zbest.zpay.shared.process.BaseAction;
import com.zbest.zpay.shared.process.ProcessResult;

/**
 * 检查入口参数
 * 
 *
 * @author Administrator
 * @version $Id: CheckPayReqInfoDataAction.java, v 0.1 2017-4-16 上午10:35:42 Administrator Exp $
 */
@Service("checkPayReqAction")
public class CheckPayReqAction extends BaseAction {

    /** 
     * @see com.zbest.zpay.shared.process.BaseAction#perform(com.zbest.zpay.shared.process.ProcessResult)
     */
    @Override
    public void perform(ProcessResult processResponse) {
        PayInfoDTO payInfoDTO = getValue(PaycoreKeyEnum.PAY_INFO.getCode());

        ValidatorUtil.validate(payInfoDTO);

        List<PaySubInfoDTO> dtoList = payInfoDTO.getPaySubInfoDTOList();

        BigDecimal totalAmount = new BigDecimal("0");
        for (PaySubInfoDTO dto : dtoList) {
            ValidatorUtil.validate(dto);
            totalAmount = totalAmount.add(dto.getAmount());
        }

        if (payInfoDTO.getAmount().compareTo(totalAmount) != 0) {
            throw new ZpayException(BizCode.PARAM_NOT_EQUAL, "明细金额与总金额不一致");
        }

    }
}
